﻿using System;

namespace CodeContrib
{
	public class RandomDouble : IRandom<double>
	{
		private readonly double _maximumValue;
		private readonly double _minimumValue;

		public double MaximumValue
		{
			get { return _maximumValue; }
		}

		public double MinimumValue
		{
			get { return _minimumValue; }
		}

		public RandomDouble() : this(double.MinValue, double.MaxValue)
		{
		}

		public RandomDouble(double maxValue) : this(double.MinValue, maxValue)
		{
		}

		public RandomDouble(double minValue, double maxValue)
		{
			if (minValue > maxValue)
			{
				throw new ArgumentOutOfRangeException("minValue", minValue, "'minValue' cannot be greater than 'maxValue'");
			}

			_maximumValue = maxValue;
			_minimumValue = minValue;
		}

		public double Next()
		{
			var random = RandomSingleton.Instance.Random;

			return random.NextDouble() * (_maximumValue - _minimumValue) + _minimumValue;
		}
	}
}